{template 'header'}
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">任务管理</a>
        <a>
          <cite>任务列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <input type="text" name="taskid" placeholder="请输入任务ID" autocomplete="off" class="layui-input"
                   value="{$taskid}">
            <input class="layui-input" autocomplete="off" placeholder="任务开始时间" name="start_time" id="start_time"
                   value="{$_GPC['start_time']}">
            <input class="layui-input" autocomplete="off" placeholder="任务结束时间" name="end_time" id="end_time"
                   value="{$_GPC['end_time']}">
            <input type="text" name="title" placeholder="请输入任务标题" autocomplete="off" class="layui-input"
                   value="{$title}">
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="x_admin_show('发布任务','{php echo $this->createWebUrl('task_list',['op'=>'add'])}')"><i class="layui-icon"></i>添加
        </button>
        <span class="x-right" style="line-height:40px">共有数据：{$total}条</span>
    </xblock>
    <table class="layui-table x-admin">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                        class="layui-icon">&#xe605;</i></div>
            </th>
            <th>ID</th>
            <th>任务名称</th>
            <th>缩略图</th>
            <th>任务金额</th>
            <th>开始时间</th>
            <th>结束时间</th>
            <th>发布数量</th>
            <th>已抢数量</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {loop $list $item}
        <tr>
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$item["id"]}'><i
                        class="layui-icon">&#xe605;</i></div>
            </td>
            <td>{$item['id']}</td>
            <td>{$item['title']}</td>
            <td width="120" height="120">
                {if empty($item['thumb'])}
                暂无图片{else}
                <img src="{php echo cmf_get_upload_url($item['thumb'])}" alt="">
                {/if}
            </td>
            <td>{$item['task_money']}</td>
            <td>{php echo date('Y-m-d H:i:s',$item['begin_time'])}</td>
            <td>{php echo date('Y-m-d H:i:s',$item['end_time'])}</td>
            <td>{$item['release_num']}</td>
            <td>{$item['receive_num']}</td>
            <td>{php echo date('Y-m-d H:i:s',$item['create_time'])}</td>
            <td class="td-manage">
                <a title="编辑" onclick="x_admin_show('编辑','{php echo $this->createWebUrl('task_list',['op'=>'edit','id'=>$item['id']])}')"
                   href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a title="删除" onclick="task_del(this,{$item['id']})" href="javascript:;">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
        </tr>
        {/loop}
        </tbody>
    </table>
    <div class="page">
        {$pager}
    </div>

</div>
<script>
    layui.use(['jquery', 'layer', 'form'], function () {
        var $ = layui.jquery
            , layer = layui.layer
            , form = layui.form

        //监听提交
        form.on('submit(sreach)', function (data) {
            console.log(data.field)
            var str = '';
            for (var key in data.field) {
                str += key + "=" + data.field[key] + "&";
            }
            var url = '{php echo $this->createWebUrl("task_list")}'
            location.href = url + "&" + str;
            return false;
        });

        $('table img').click(function () {
            console.log($(this).attr('src'))
            var imgSrc = $(this).attr('src')
            layer.open({
                type: 1
                , title: false
                , closeBtn: 0
                , skin: 'layui-layer-nobg'
                , shadeClose: true
                , content: '<img src="' + imgSrc + '" style="max-height:600px;max-width:100%;">'
                , scrollbar: false
            })
        })
    })
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start_time', //指定元素
            type: 'datetime'
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end_time', //指定元素
            type: 'datetime'
        });
    });

    /*删除*/
    function task_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            var url = '{php echo $this->createWebUrl("task_list",array("op"=>"del"))}'
            $.post(url, {id}, function (ret) {
                if (ret.code) {
                    $(obj).parents("tr").remove();
                    layer.msg(ret.msg, {icon: 1, time: 1000});
                } else {
                    layer.msg(ret.msg, {icon: 0});
                }
            }, 'json')
        });
    }


    function delAll(argument) {

        var data = tableCheck.getData();

        layer.confirm('确认要删除吗？' + data, function (index) {
            //捉到所有被选中的，发异步进行删除
            var url = '{php echo $this->createWebUrl("task_list",array("op"=>"del"))}'
            $.post(url, {'ids': data}, function (ret) {
                console.log(ret)
                if (ret.code) {
                    layer.msg(ret.msg, {icon: 1});
                    $(".layui-form-checked").not('.header').parents('tr').remove();
                } else {
                    layer.msg(ret.msg, {icon: 0});
                }
            }, 'json')
        });
    }
</script>
<script>var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>